
<template>
  <div class="app-container">

    <el-form  :model="form" label-width="120px">
      <el-form-item label="" >
      课程名称
        <el-input v-model="form.title" style="width: 200px" />
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        课程状态
        <el-select v-model="form.status" placeholder="课程状态">
          <el-option label="未发布" value="Draft"></el-option>
          <el-option label="已发布" value="Normal"></el-option>
        </el-select>
        <el-button type="primary" @click="onSubmit">搜索</el-button>
        <el-button @click="onCancel">置空</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="课程名称">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="课程状态" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.status=='Draft'?'未发布':"已发布" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="课时数" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.lessonNum }}
        </template>
      </el-table-column>
      <el-table-column label="添加时间"  prop="eduCreate" width="110" align="center">
      </el-table-column>
      <el-table-column align="center"  label="浏览数量" width="200">
        <template slot-scope="scope">
          <span>{{ scope.row.viewCount }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center"  label="操作" width="700">
        <template slot-scope="scope">
          <el-button type="primary"   icon="el-icon-edit" @click="updatSave(scope.row.id)">编辑课程基本信息</el-button>
          <el-button type="primary"  icon="el-icon-edit" @click="updatechapter(scope.row.id)">编课程大纲基本信息</el-button>
          <el-button type="danger"  icon="el-icon-delete"  @click="del(scope.row.id)">删除课程基本信息</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      layout="prev, pager, next"
      :total="total"
      :page-size="3"
      :page-count="pagecount"
      @current-change="current"
    >
    </el-pagination>
  </div>

</template>
<script>

import {getSubjectList} from "@/api/subject";
import {getPage,getdel} from "@/api/course"

export default {
  data() {
    return {
      form:{
        status:'',
        title:'',
        pagenum:0
      },
      total:0,
      pagecount:0,
      list:null,
      listLoading:null,
    };
  },
  methods: {
    updatSave(id){
      this.$router.push({path:'/course/save',query:{saveid:id}})
    },
    updatechapter(id){
      this.$router.push({path:'/course/chapter',query:{id:id}})
    },
    current(val){
      this.form.pagenum=val
      this.fetchData();
    },
    onSubmit(){
    this.fetchData()
    },
    fetchData() {
      this.listLoading = true
      getPage(this.form).then(response => {
        this.list = response.data.records
        this.form.pagenum=response.data.current
        this.pagecount=response.data.pages
        this.total=response.data.total
        this.listLoading = false
      })
    },
    del(id){
      getdel(id).then(response => {
         if (response.code==20000){
           this.$message.success("删除成功!")
           this.fetchData()
         }else{
           this.$message.error("删除失败!")
         }
      })
    },
    onCancel(){
      this.form={}
    }
  },

  created() {
   this.fetchData()
  }
}
</script>
<style scoped lang="scss">

</style>
